package com.self.raft;

public class Vote {

    /**
     * 选票发送者id
     */
    private int senderPeerId;

    /**
     * 发送者推举的leader id
     */
    private int votePeerId;

    /**
     * 选票接受者
     */
    private int acceptPeerId;

    /**
     * 选举周期
     */
    private int epoch;

    /**
     * 0:结束; 1:进行中,-1: 表示的是心跳消息(暂用Vote代替心跳)
     */
    private int state;

    public Vote(int senderPeerId,int votePeerId,int acceptPeerId,int epoch,int state) {
        this.senderPeerId = senderPeerId;
        this.votePeerId = votePeerId;
        this.epoch = epoch;
        this.acceptPeerId = acceptPeerId;
        this.state = state;
    }

    public int getSenderPeerId() {
        return senderPeerId;
    }

    public void setSenderPeerId(int senderPeerId) {
        this.senderPeerId = senderPeerId;
    }

    public int getVotePeerId() {
        return votePeerId;
    }

    public void setVotePeerId(int votePeerId) {
        this.votePeerId = votePeerId;
    }

    public int getEpoch() {
        return epoch;
    }

    public void setEpoch(int epoch) {
        this.epoch = epoch;
    }

    public int getAcceptPeerId() {
        return acceptPeerId;
    }

    public void setAcceptPeerId(int acceptPeerId) {
        this.acceptPeerId = acceptPeerId;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Vote vote = (Vote) o;

        if (senderPeerId != vote.senderPeerId) return false;
        if (votePeerId != vote.votePeerId) return false;
        if (acceptPeerId != vote.acceptPeerId) return false;
        if (epoch != vote.epoch) return false;
        return state == vote.state;
    }

    @Override
    public int hashCode() {
        int result = senderPeerId;
        result = 31 * result + votePeerId;
        result = 31 * result + acceptPeerId;
        result = 31 * result + epoch;
        result = 31 * result + state;
        return result;
    }

    @Override
    public String toString() {
        return "Vote{" +
                "senderPeerId=" + senderPeerId +
                ", votePeerId=" + votePeerId +
                ", acceptPeerId=" + acceptPeerId +
                ", epoch=" + epoch +
                ", state=" + state +
                '}';
    }
}
